/**
 * Copyright © 2024 北京迅安网络系统有限责任公司 Co., Ltd. All rights reserved.
 */

#include "osid_interface.h"
#include "hilog_util.h"
/**
 * 获取OSID的服务
 */
static sptr<IOsidManager> getOsidService(int serviceId)
{
    sptr<ISystemAbilityManager> sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
    sptr<IRemoteObject> object = sm->GetSystemAbility(serviceId);
    if (object == nullptr) {
        HILOGE("get osid sa failed.");
    }
    sptr<IOsidManager> result = iface_cast<IOsidManager>(object);
    return result;
}

std::string friGetOSID()
{
    sptr<IOsidManager> osidManager = getOsidService(OSID_SERVICE_ID);
    if (osidManager == nullptr) {
        HILOGI("friGetOSID failed.");
        return "";
    }
    return osidManager->friGetDeviceOSID();
}

std::string friGetPMSID()
{
    sptr<IOsidManager> osidManager = getOsidService(OSID_SERVICE_ID);
    if (osidManager == nullptr) {
        HILOGI("friGetPMSID failed.");
        return "";
    }
    return osidManager->friGetDevicePMSID();
}

bool friCheckOSID(std::string osid)
{
    sptr<IOsidManager> osidManager = getOsidService(OSID_SERVICE_ID);
    if (osidManager == nullptr) {
        HILOGI("friCheckOSID failed.");
        return false;
    }
    return osidManager->friCheckOSID(osid);
}

bool friCheckPMSID(std::string pmsid)
{
    sptr<IOsidManager> osidManager = getOsidService(OSID_SERVICE_ID);
    if (osidManager == nullptr) {
        HILOGI("friCheckPMSID failed.");
        return false;
    }
    return osidManager->friCheckPMSID(pmsid);
}

std::string friGetCert()
{
    sptr<IOsidManager> osidManager = getOsidService(OSID_SERVICE_ID);
    if (osidManager == nullptr) {
        HILOGI("friGetCert failed.");
        return "";
    }

    return osidManager->friGetRealCert();
}